using System.IO;

namespace Engine.FileFormats3D.C11Syndikat
{
    internal class C11Vertex
    {
        #region Private Fields

        private int data1;

        // +4 = 36
        private int data2;

        private int normalX, normalY, normalZ, normal0;
        private float textureU, textureV, textureW, textureX;

        // total 40 Byte
        private float x, y, z;

        #endregion Private Fields

        #region Public Properties

        // Color
        public int Data1
        {
            get { return data1; }
            set { data1 = value; }
        }

        public int Data2
        {
            get { return data2; }
            set { data2 = value; }
        }

        //+4 byte = 16
        public int Normal0
        {
            get { return normal0; }
            set { normal0 = value; }
        }

        public int NormalX
        {
            get { return normalX; }
            set { normalX = value; }
        }

        public int NormalY
        {
            get { return normalY; }
            set { normalY = value; }
        }

        public int NormalZ
        {
            get { return normalZ; }
            set { normalZ = value; }
        }

        public float TextureU
        {
            get { return textureU; }
            set { textureU = value; }
        }

        public float TextureV
        {
            get { return textureV; }
            set { textureV = value; }
        }

        public float TextureW
        {
            get { return textureW; }
            set { textureW = value; }
        }

        // + 16 = 32
        public float TextureX
        {
            get { return textureX; }
            set { textureX = value; }
        }

        public float X
        {
            get { return x; }
            set { x = value; }
        }

        public float Y
        {
            get { return y; }
            set { y = value; }
        }

        //12 Byte
        public float Z
        {
            get { return z; }
            set { z = value; }
        }

        #endregion Public Properties

        #region Internal Methods

        // +4 = 40
        internal static C11Vertex FromStream(BinaryReader br)
        {
            C11Vertex vertex = new C11Vertex();

            vertex.X = br.ReadSingle();
            vertex.Y = br.ReadSingle();
            vertex.Z = br.ReadSingle();
            vertex.NormalX = (int)br.ReadByte() - 128;
            vertex.NormalY = (int)br.ReadByte() - 128;
            vertex.NormalZ = (int)br.ReadByte() - 128;
            vertex.Normal0 = br.ReadByte();
            vertex.TextureU = br.ReadSingle();
            vertex.TextureV = br.ReadSingle();
            vertex.TextureW = br.ReadSingle();
            vertex.TextureX = br.ReadSingle();
            vertex.Data1 = br.ReadInt32();
            vertex.Data2 = br.ReadInt32();

            return vertex;
        }

        #endregion Internal Methods
    }
}